package com.k8.cluster.clusterImpl;

import com.k8.cluster.clusterInvokerImpl.FailFastClusterInvoker;
import com.k8.rpc.cluster.Cluster;
import com.k8.rpc.cluster.ClusterInvoker;
import com.k8.rpc.cluster.loadBalance.LoadBalance;
import com.k8.rpc.directory.Directory;

/**
 * @Author: k8
 * @CreateTime: 2025-03-20
 * @Version: 1.0
 */
public class FailFastCluster<T> implements Cluster<T> {
    private LoadBalance<T> loadBalance;

    @Override
    public ClusterInvoker<T> join(Directory<T> directory) {
        FailFastClusterInvoker<T> failFastClusterInvoker = new FailFastClusterInvoker<>();
        failFastClusterInvoker.setInterface(directory.type());
        loadBalance.pushInvokersDirectory(directory);
        failFastClusterInvoker.setLoadBalance(loadBalance);
        return failFastClusterInvoker;
    }

    @Override
    public void setBalance(LoadBalance<T> loadBalance) {
        this.loadBalance = loadBalance;
    }
}
